<template>
  <view>
    <view class="goods-item">
      <!-- 左侧图片区域 -->
      <view class="item-left-box">
        <radio :checked="goods.goods_state" v-if="showRdio" color="#c00000" class="goods-state" @click="radioChange"></radio>
        <image :src="goods.goods_small_logo"></image>
      </view>
      <!-- 右侧文字区域 -->
      <view class="item-right-box">
        <text class="goods-name">{{goods.goods_name}}</text>
        <view class="goods-info">
          <text class="goods-price">￥{{goods.goods_price | toFixed}}</text>
          <uni-number-box :min="1" :value="goods.goods_count" v-if="showNum" @change="numChangeHandler"></uni-number-box>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    name:"my-goods",
    data() {
      return {
        
      };
    },
    props:{
      goods:{
        type:Object,
        default:{}
      },
      showRdio:{
        type:Boolean,
        defaul:false
      },
      showNum:{
        type:Boolean,
        default:false
      }
      
    },
    filters:{
      toFixed(num){
        return Number(num).toFixed(2)
      }
    },
    methods:{
      radioChange(){
        this.$emit('radioChange',{
          goods_id:this.goods.goods_id,
          goods_state:!this.goods.goods_state
        })
      },
      numChangeHandler(val){
        this.$emit('numChange',{
          goods_id:this.goods.goods_id,
          goods_count:+val
        })
      }
    }
    
  }
</script>

<style lang="scss">
.goods-item{
  display: flex;
  padding: 10px 0;
  margin: 5px;
  border-bottom: 1px solid #eeeeee;
  .item-left-box{
    display: flex;
    align-items: center;
    justify-content: space-between;
    image{
      width: 100px;
      height: 100px;
      display: block;
      margin-right: 5px;
    }
  }
  .item-right-box{
    display: flex;
    flex: 1;
    flex-direction: column;
    justify-content: space-between;
    .goods-name{
      font-size: 13px;
    }
    .goods-info{
      display: flex;
      align-items: center;
      justify-content: space-between;
      .goods-price{
        color: #c00000;
        font-size: 16px;
      }
    }
    
  }
}
</style>